﻿Imports System.Data.OleDb
Imports DTO

Public Class QuyDinhDAO

    Public Function CapNhatQuyDinh(ByVal quydinh As QuyDinhDTO) As Boolean
        Dim kq As Boolean = True
        Dim cn As OleDbConnection
        'B1 & B2: Tao chuoi ket noi, mo ket noi bang doi tuong ket noi
        cn = DatabaseProvider.ConnectionData()
        'B3: Tao chuoi strSQL thao tac CSDL
        Dim sql As String = "Update QuyDinh set SoLuongSachNhapMin = ?, SoLuongTonMin = ? ,NoToiDa = ?, LuongTonSauKhiBan = ?"
        Dim cmd As New OleDbCommand(sql, cn)
        cmd.Parameters.Add("@SoLuongSachNhapMin", OleDbType.Integer)
        cmd.Parameters.Add("@SoLuongTonMin", OleDbType.Integer)
        cmd.Parameters.Add("@NoToiDa", OleDbType.Integer)
        cmd.Parameters.Add("@LuongTonSauKhiBan", OleDbType.Integer)
        ' cmd.Parameters.Add("@SoTienNo", OleDbType.Integer)

        cmd.Parameters("@SoLuongSachNhapMin").Value = quydinh.laySoLuongNhapMin
        cmd.Parameters("@SoLuongTonMin").Value = quydinh.LaySoLuongTonMin
        cmd.Parameters("@NoToiDa").Value = quydinh.LayNoToiDa
        cmd.Parameters("@LuongTonSauKhiBan").Value = quydinh.LayLuongTonSauKhiBan
        '   cmd.Parameters("@SoTienNo").Value = quydinh.LayTienNo


        cmd.ExecuteNonQuery()
        Dim i As Integer = 9
        i = cmd.ExecuteNonQuery()
        If i <> 9 Then
            kq = True
        Else
            kq = False
        End If
        cn.Close()
        Return kq
    End Function

    Public Function CapNhatQuyDinhMacDinh() As Boolean
        Dim kq As Boolean = True
        Dim cn As OleDbConnection
        'B1 & B2: Tao chuoi ket noi, mo ket noi bang doi tuong ket noi
        cn = DatabaseProvider.ConnectionData()
        'B3: Tao chuoi strSQL thao tac CSDL
        Dim sql As String = "Update QuyDinh set SoLuongSachNhapMin = ?, SoLuongTonMin = ? ,NoToiDa = ?, LuongTonSauKhiBan = ?"
        Dim cmd As New OleDbCommand(sql, cn)
        cmd.Parameters.Add("@SoLuongSachNhapMin", OleDbType.Integer)
        cmd.Parameters.Add("@SoLuongTonMin", OleDbType.Integer)
        cmd.Parameters.Add("@NoToiDa", OleDbType.Integer)
        cmd.Parameters.Add("@LuongTonSauKhiBan", OleDbType.Integer)
        ' cmd.Parameters.Add("@SoTienNo", OleDbType.Integer)

        cmd.Parameters("@SoLuongSachNhapMin").Value = 150
        cmd.Parameters("@SoLuongTonMin").Value = 300
        cmd.Parameters("@NoToiDa").Value = 20000
        cmd.Parameters("@LuongTonSauKhiBan").Value = 20
        '   cmd.Parameters("@SoTienNo").Value = quydinh.LayTienNo


        cmd.ExecuteNonQuery()
        Dim i As Integer = 9
        i = cmd.ExecuteNonQuery()
        If i <> 9 Then
            kq = True
        Else
            kq = False
        End If
        cn.Close()
        Return kq
    End Function

    Public Function LayQuyDinh() As DataTable
        Dim kq As New DataTable
        Dim cn As OleDbConnection
        'B1 & B2: Tao chuoi ket noi, mo ket noi bang doi tuong ket noi
        cn = DatabaseProvider.ConnectionData()
        'B3: Tao chuoi strSQL thao tac CSDL
        Dim sql As String = "select * from QuyDinh where DaXoa=0"
        Dim a As New OleDb.OleDbDataAdapter(sql, cn)
        a.Fill(kq)
        cn.Close()
        Return kq
    End Function

End Class
